<!-- 转账 -->
<template>
	<view class="content">
		<view class="zview">
			<view class="zitem">
				<view class="lval">
					<!-- <image class="zimg" src="/static/images/cuowu.png" mode="" /> -->
					<text class="zname">商品标题</text>
				</view>
				<u-input v-model="mpfabu.title" type="text" :border="false" placeholder="请输入商品标题"/>
			</view>
			<view class="zitem" style="display: flex;flex-direction: column;align-items: flex-start;">
				<view class="lval">
					<!-- <image class="zimg" src="/static/images/cuowu.png" mode="" /> -->
					<text class="zname">文字描述</text>
				</view>
				<u-input v-model="mpfabu.content" style="width: 100%;margin-top: 10rpx;" type="textarea" :border="false" placeholder="请输入文字描述"/>
			</view>
			<view class="zitem" style="display: flex;flex-direction: column;align-items: flex-start;">
				<view class="lval">
					<text class="zname">需求图</text>
				</view>
				<view class="leiitem col buviewtwo">
					<view class="tuview">
						<view class="tuitem" @click="uploadtwo(1)" v-if="mpfabu.image.length<3">
							<image class="addtu" src="/static/images/btn_tupian.png"></image>
						</view>
						<view class="tuitem" v-for="(item,index) in mpfabu.image" :key="index">
								<!-- <view class="cha" @click="del(1,index)">
									<image class="shanicon" src="/static/images/shanicon.png"></image>
								</view> -->
								<image class="addtu" :src="item"></image>
							</view>
						</view>
					</view>
			</view>
			<view class="zitem" @click="leishow=true" style="padding: 25rpx 0;">
				<view class="lval">
					<text class="zname">行业类别</text>
				</view>
				<view class="ml">
					<text class="xuan">{{ mpfabu.label?mpfabu.label:'请选择' }}</text>
					<image class="nav_icon_back" src="/static/images/nav_icon_back.png"></image>
				</view>
			</view>
		</view>
		<view class="tijiao" @click="gettijiao">提交</view>

		<u-select :list="slist" v-model="leishow" @confirm="selectConfirm"></u-select>
	</view>
</template>

<script>
import {
	BASE_URL
} from '@/env.js'
	import { mapState, mapActions, mapGetters } from 'vuex';
	export default {
		components: {},
		data() {
			return {
				account:'',
				list: [
					{
						name: '易货额',
						disabled: false
					},
					{
						name: '现金',
						disabled: false
					}
				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '易货额',
				mpfabu:{
					image:[],
					label:'',
					cid:'',
					title:'',
					content:'',
					
				},
				leishow: false,
				slist: [
					// {
					// 	value: '1',
					// 	label: '江'
					// },
					// {
					// 	value: '2',
					// 	label: '湖'
					// }
				],
				headimg:''
			};
		},
		computed: {
		},
		onLoad() {
			this.getinit()
			// console.log(BASE_URL)
		},
		// 触底加载更多
		onReachBottom() {
		},
		methods: {
			getinit() {
				let that = this;
				that.$http('home.needgetCate', {
				}).then(res => {
					if (res.code === 1) {
						let data = res.data
						let slist = []
						for(let i in data){
							let a = {}
							a.label = data[i].name
							a.value = data[i].id
							slist.push(a)
						}
						that.slist = slist
					}
				});
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				// console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				// console.log(e);
			},
			selectConfirm(e){
				console.log(e)
				this.mpfabu.label = e[0].label
				this.mpfabu.cid = e[0].value
			},
			uploadtwo(e,index) {
				this.updatetype = e
				this.bindex = index
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.headimg = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
						// this.getavatar();//修改信息
					}
				});
			},
			unloadtou(){
				// console.log(this.head_portrait)
				let that = this
				uni.uploadFile({
					// url: baseUrl + '/api/uploadImage', //仅为示例，非真实的接口地址
					url: BASE_URL + '/api/common/upload', //仅为示例，非真实的接口地址
					filePath: this.headimg,
					name: 'file',
					header: {
						// 'content-type': 'application/json;charset=UTF-8',
						'token':uni.getStorageSync('token'),
					},
					formData: {
						'token':uni.getStorageSync('token'),
					},
					success: (uploadFileRes) => {
						console.log( JSON.parse(uploadFileRes.data).data);
						let mpfabu = that.mpfabu
						if(that.updatetype==1){
							//图片
							mpfabu.image.push(JSON.parse(uploadFileRes.data).data.fullurl)
						}
					}
				});
			},
			gettijiao(){
				
				let that = this;
				if(!that.mpfabu.title){
					this.$u.toast('请输入标题');
					return false;
				}
				if(!that.mpfabu.content){
					this.$u.toast('请输入文字描述');
					return false;
				}
				if(!that.mpfabu.cid){
					this.$u.toast('请选择行业类别');
					return false;
				}
				if(!that.mpfabu.image){
					this.$u.toast('请选择图片');
					return false;
				}
				that.$http('home.needadd', {
					cid:that.mpfabu.cid,
					title:that.mpfabu.title,
					content:that.mpfabu.content,
					images:that.mpfabu.image.toString()
				}).then(res => {
					if (res.code === 1) {
						this.$u.toast(res.msg);

					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	// 钱包记录
	.content {
		.zview{
			margin: 30rpx;
			border-radius: 10rpx;
			background-color: #fff;
			padding: 10rpx 30rpx;
			
			.zitem{
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 20rpx 0;
				border-bottom: 1rpx solid #eee;
			}
			.zitem:last-child{
				border-bottom: none;
			}
			.zimg{
				width: 35rpx;
				height: 35rpx;
				margin-right: 8rpx;
			}
			.zname{
				color: #333;
				font-size: 30rpx;
				font-weight: normal;
				display: inline-block;
				margin-right: 10rpx;
			}
		}
		.lval{
			width: 180rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
		}
	}
	.tijiao{
		margin: 50rpx 30rpx;
		height: 80rpx;
		background-color:#ff6d00;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 30rpx;
		font-weight: normal;
		border-radius: 10rpx;
	}
	.leiitem{
		margin-top: 20rpx;
	}
	.tuview{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		// margin-top: 30rpx;
		.tuitem{
			width: 180rpx;
			height: 180rpx;
			position: relative;
			border-radius: 10rpx;
			margin: 0 20rpx 20rpx 0;
			.addtu{
				position: absolute;
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
			.cha{
				background-color: rgba(0, 0, 0, 0.4);
				position: absolute;
				width: 100%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10rpx;
				z-index: 10;
				text{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
				}
				.shanicon{
					position: relative;
					width: 50rpx;
					height: 50rpx;
					// right: 20rpx;
					// top: 20rpx;
				}
			}
		}
	}
	.xuan{
		font-weight: 400;
		font-size: 26rpx;
		color: #666;
	}
	.nav_icon_back{
		margin-left: 20rpx;
		width: 24rpx;
		height: 24rpx;
	}
	.ml{
		margin-left: auto;
	}
</style>
